var clear = document.querySelector("#clear");
var result = document.querySelector("#result");
var aSpan = document.querySelectorAll("span");
var oInput = document.querySelector("input");
var str = "";

clear.onclick = function () {
  str = "";
  oInput.value = "";
}

result.onclick = function () {
  oInput.value = eval(oInput.value);
  str = eval(oInput.value); //eval()-->函数将字符串当作运算式计算
}

for (var i = 0; i < aSpan.length; i++) {
  aSpan[i].onclick = function () {
    str += this.innerHTML;
    oInput.value = str;
  }
}